package com.yushutao.menu.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.yushutao.menu.beans.DishBean;
import com.yushutao.menu.dao.IDish;
import com.yushutao.menu.dao.MyBatisUtil;

public class DishDAO implements IDish{

	@Override
	public void addDish(DishBean dish) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IDish mapper = session.getMapper(IDish.class);
			mapper.addDish(dish);
			session.commit();
		}
	}

	@Override
	public void removeDishById(int id) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IDish mapper = session.getMapper(IDish.class);
			mapper.removeDishById(id);
			session.commit();
		}
	}

	@Override
	public DishBean getDishById(int id) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IDish mapper = session.getMapper(IDish.class);
			return mapper.getDishById(id);
		}
	}

	@Override
	public List<DishBean> getAllDish() {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IDish mapper = session.getMapper(IDish.class);
			return mapper.getAllDish();
		}
	}

}
